package com.dpp.mapper;

import com.dpp.entity.Orders;
import com.dpp.entity.TakeOrders;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface TakeOrderMapper {

    /**
     * 查询历史接单信息
     * @param openid
     * @return
     */
    @Select("select t1.id, t1.number, t1.openid, t1.takeorder_time, t1.take_time, t1.delivery_time,t3.order_type,t2.count  from take_orders t1 ,orders t2,product_info t3 where t1.openid = #{openid} and t1.number=t2.number and t2.product_id=t3.id and t2.order_status in (2,21,22,23,24,25) order by t2.order_status asc ,create_time desc")
    List<TakeOrders> selectTakes20(String openid);
    @Select("select t1.id, t1.number, t1.openid, t1.takeorder_time, t1.take_time, t1.delivery_time,t3.order_type,t2.count  from take_orders t1 ,orders t2,product_info t3 where t1.openid = #{openid} and t1.number=t2.number and t2.product_id=t3.id and t2.order_status in (3,4,-2,-3) order by t2.order_status asc ,create_time desc")
    List<TakeOrders> selectTakes1(String openid);
    @Select("select t1.id, t1.number, t1.openid, t1.takeorder_time, t1.take_time, t1.delivery_time,t3.order_type,t2.count  from take_orders t1 ,orders t2,product_info t3 where t1.openid = #{openid} and t1.number=t2.number and t2.product_id=t3.id and t2.order_status in (5) order by t2.order_status asc , t2.update_time desc ")
    List<TakeOrders> selectTakes2(String openid);

    @Insert("insert into take_orders(number,openid,takeorder_time)" +
            "values(#{number},#{openid},#{now})")
    void insert(Long number, String openid, LocalDateTime now);

    @Select("select * from take_orders where number = #{number}")
    TakeOrders selectById(Long number);
    @Select("select DISTINCT t1.id, t1.number, t1.openid, t1.takeorder_time, t1.take_time, t1.delivery_time,t3.order_type,t2.order_status " +
            " from take_orders t1 ,orders t2,product_info t3 ,orders_detail t4 where " +
            "t1.openid = #{openid} and t1.number=t2.number and t2.product_id=t3.id and t2.id=t4.order_id and t4.address Like  concat('%', #{path}, '%') and t2.order_status in (2,3,4) order by t2.order_status asc")
    List<TakeOrders> selectPathTakes1(String openid,String path);
    @Select("select DISTINCT t1.id, t1.number, t1.openid, t1.takeorder_time, t1.take_time, t1.delivery_time,t3.order_type ,t2.order_status,t2.update_time " +
            "from take_orders t1 ,orders t2,product_info t3 ,orders_detail t4 where " +
            "t1.openid = #{openid} and t1.number=t2.number and t2.product_id=t3.id  and t2.id=t4.order_id and t4.address Like   concat('%', #{path}, '%') and t2.order_status in (5) order by t2.order_status asc , t2.update_time desc ")
    List<TakeOrders> selectPathTakes2(String openid,String path);
    @Delete("DELETE From take_orders where number =#{number} ")
    void DeleteByNumber(Long number);
}
